package listbyorder.access101_200.test122;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/8 13:09
 */
public class Solution1 {

    // 方法一； 计算出间距，利润数组，然后把大于0的累加即可
    public int maxProfit(int[] prices) {
        int ans = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            ans += Math.max(prices[i + 1] - prices[i], 0);
        }
        return ans;
    }
}
